package com.rupertjones.globalcron.util;

import static java.lang.String.format;

/**
 * <p>&copy Rupert Jones 2012</p>
 *
 * @author rup
 */
public class TypeConverter {

    public static Object convert(String value, Class type) {
        try {
            if (type.getClass().equals(Boolean.class.getClass())) {
                return convertBoolean(value);
            }
        } catch (Throwable th) {
            throw new RuntimeException(format("Could not convert [%s] to type [%s]", value, type.getName()));
        }
        throw new RuntimeException(format("Conversion not available for [%s] to type [%s]", value, type.getName()));
    }

    private static Boolean convertBoolean(String value) {
        return Boolean.valueOf(value);
    }
}
